package com.ahp.dao.impl;

import java.util.List;

import com.ahp.bean.Factor;
import com.ahp.dao.FactorDao;

public class FactorDaoImpl extends GenericDAOImpl<Factor, Integer> implements FactorDao {
	
	public FactorDaoImpl() {
		super(Factor.class);
	}

	public FactorDaoImpl(Class<Factor> clazz) {
		super(clazz);
	}

	public boolean addFirstFactor(Factor factor){
		try{
			this.getHibernateTemplate().save(factor);
			return true;
		}catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	public List<Factor> findFirstFactor(int id) {
		String sql = "from Factor f where f.module.modId=? and f.level=1";
		List re = this.getHibernateTemplate().find(sql,id);
		return re;
	}
	
	public List<Factor> findSecondFactor(int id) {
		String sql = "from Factor f where f.pid=? and f.level=2";
		List re = this.getHibernateTemplate().find(sql,id);
		return re;
	}
	
	public List<Factor> SecondFactor(int id) {
		String sql = "from Factor f where f.module.modId=? and f.level=2";
		List re = this.getHibernateTemplate().find(sql,id);
		return re;
	}
	
	public boolean removeFactor(int id){
		try{
			this.getHibernateTemplate().delete((Factor)this.getHibernateTemplate().get(Factor.class, id));
			return true;
		}catch (Exception e) {
			return false;
		}
	}
}
